/**
 * NearShop
 * ProtocolHelper.java
 * com.android.nearshop.io.protocol.util
 * 
 */
package com.android.nearshop.io.protocol.in;


/*********************************************************
 * @author : zhaohua
 * @version : 2012-8-11
 * @see : 协议的帮助类，主要是处理重复的协议
 * @Copyright : copyrights reserved by personal 2007-2012
 **********************************************************/
public class ProtocolHelper
{

    /**
     * 排序方式有三种：距离、星级、访问量；
     * @param distance 是否按距离
     * @param distanceDesc ture：降序，否则升序
     * @param recommend 是否按星级
     * @param recommendDesc ture：降序，否则升序
     * @param clickrates 是否按访问量
     * @param clickratesDesc ture：降序，否则升序
     */
    public static void setOrderStruct(
            SoapAction<?> action,
            boolean distance, boolean distanceDesc,
            boolean recommend , boolean recommendDesc,
            boolean clickrates , boolean clickratesDesc)
    {
        if( !distance && !recommend && !clickrates) return;
        StringBuilder buf = new StringBuilder();
        boolean dotable = false;
        if(distance)
        {
            buf.append("distance");
            buf.append(" " + (distanceDesc ? "desc" : "asc"));
            dotable = true;
        }
        if(recommend)
        {
            if(dotable) buf.append(",");
            buf.append("recommend");
            buf.append(" " + (recommendDesc ? "desc" : "asc"));
            dotable = true;
        }
        if(clickrates)
        {
            if(dotable) buf.append(",");
            buf.append("clickrates");
            buf.append(" " + (clickratesDesc ? "desc" : "asc"));
            dotable = true;
        }
        action.addJsonParam("orderStruct",buf.toString());
    }
    
}
